﻿using System;
using System.Text;
using System.Windows.Forms;

namespace dem1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int sesn = 0;
            int viStatus;
            int vi = 0;
            int retCount;
            byte[] bytes = new byte[255];
            viStatus = visa32.viOpenDefaultRM(out sesn);//打开VISA资源管理器句柄
            viStatus = visa32.viOpen(sesn, "TCPIP0::172.141.64.51::5025::SOCKET", visa32.VI_NO_LOCK, visa32.VI_TMO_IMMEDIATE, out vi);//打开仪器句柄。TCPIP0::172.141.64.51::5025::SOCKET为网络分析仪的IP地址和端口号。这里使用的是我的配置，要根据自己的情况进行改动。    
            viStatus = visa32.viPrintf(vi, "*IDN?\n");//查询仪器标识
            viStatus = visa32.viRead(vi, bytes, 79, out retCount);
            visa32.viClose(vi);//关闭VISA资源管理器
            visa32.viClose(sesn);//关闭仪器
            string idnStr = Encoding.ASCII.GetString(bytes, 0, bytes.Length);//byte[]转字符串
            textBox1.Text = idnStr;
            idnStr = null;
        }
    }
}
